﻿using BUS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using DAO;

namespace MyWeb.GUI.User
{
    public partial class TrangChu : System.Web.UI.Page
    {
        DataProvider db = new DataProvider();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) // Lệnh kiểm tra postback từ server
            {
                LoadSanPham();              
            }
        }
        private void LoadSanPham()
        {
            // đổ giữ liệu cho 2 rep
            RpSanPham.DataSource = db.LayDuLieuThamSo("LoadSanPham", CommandType.StoredProcedure);
            RpSanPham.DataBind();

            RpSanPham1.DataSource = db.LayDuLieuThamSo("LoadSanPham", CommandType.StoredProcedure);
            RpSanPham1.DataBind();

        }
       

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("SanPham.aspx");
        }

        protected void RpSanPham_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddCart"))
            {
                int masp = Convert.ToInt32(e.CommandArgument);
                ShoppingCart.Instance.AddItem(masp);
                Response.Redirect("TrangChu.aspx");
            }


            if (e.CommandName.Equals("Detail"))
            {
                int proId = Convert.ToInt32(e.CommandArgument);
                Response.Redirect("ChiTietSanPham.aspx?MaSP=" + proId);
            }
        }
    }
}